package com.SinaMicroblogging;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.SinaMicroblogging.Extension.ImageAdapter;
import com.SinaMicroblogging.TabFocused.ITabFocused;
import com.SinaMicroblogging.TabFocused.TabAssember;
import com.SinaMicroblogging.TabFocused.TabEnum;

import android.app.AlertDialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TabHost;
import android.widget.WrapperListAdapter;
import android.widget.TabHost.TabSpec;
import android.widget.TabHost.OnTabChangeListener;

public class MainPage extends PageBase implements TabHost.OnTabChangeListener,
		OnScrollListener, OnItemClickListener {

	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		new AlertDialog.Builder(this).setTitle("Message").setMessage(
				"Confirm to exit?").setPositiveButton("Ok",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dlg, int something) {
						MainPage.super.onBackPressed();
					}
				}).setNegativeButton("Cancel",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dlg, int something) {
					}
				}).show();
	}

	private TabHost tabHost;
	ITabFocused tabFocused;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mainpage);
		tabHost = (TabHost) findViewById(R.id.tabhost);

		if (tabHost != null) {
			tabHost.setup();

			TabFactory.CreateTabSpec(tabHost, R.layout.tabhome, R.id.tabhome,
					TabEnum.Home.toString(), getResources().getDrawable(
							R.drawable.tabhomeheader));

			TabFactory.CreateTabSpec(tabHost, R.layout.tabmessage,
					R.id.tabmessage, TabEnum.Message.toString(), getResources()
							.getDrawable(R.drawable.tabmessageheader));

			TabFactory.CreateTabSpec(tabHost, R.layout.tabpersonal,
					R.id.tabpersonal, TabEnum.Personal.toString(),
					getResources().getDrawable(R.drawable.tabpersonalheader));

			TabFactory.CreateTabSpec(tabHost, R.layout.tabsearch,
					R.id.tabsearch, TabEnum.Search.toString(), getResources()
							.getDrawable(R.drawable.tabsearchheader));

			tabHost.setOnTabChangedListener(this);
			tabHost.setCurrentTab(0);
			onTabChanged(TabEnum.Home.toString());
		}
	}

	@Override
	public void onTabChanged(String tabId) {
		// TODO Auto-generated method stub
		tabFocused = TabAssember.getTabFocused(tabId);
		tabFocused.OnTabFocused(this);
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		tabFocused.onItemClick(arg0, arg1, arg2, arg3);
	}

	@Override
	public void onScroll(AbsListView view, int firstVisibleItem,
			int visibleItemCount, int totalItemCount) {
		// TODO Auto-generated method stub
		tabFocused.onScroll(view, firstVisibleItem, visibleItemCount,
				totalItemCount);

	}

	@Override
	public void onScrollStateChanged(AbsListView view, int scrollState) {
		// TODO Auto-generated method stub
		tabFocused.onScrollStateChanged(view, scrollState);
	}

}
